package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.DishDto;
import com.itheima.reggie.entity.SetmealDto;
import com.itheima.reggie.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    public R addDish(@RequestBody DishDto dishDto) {
        R r = dishService.add(dishDto);
        return r;
    }

    @GetMapping("/page")
    public R fingPage(Integer page, Integer pageSize, String name) {
        R r = dishService.findPage(page, pageSize, name);
        return r;
    }

    @GetMapping("/{id}")
    public R findById(@PathVariable Long id) {
        R r = dishService.findById(id);
        return r;
    }

    @PutMapping
    public R modify(@RequestBody DishDto dishDto) {
        dishService.modify(dishDto);
        return R.success("修改成功");
    }

    @DeleteMapping
    public R remove(Long[] ids) {
        dishService.remove(ids);
        return R.success("删除成功");
    }


    @PostMapping("/status/{id}")
    public R modifyStatus(Long[] ids, @PathVariable Integer id) {
        dishService.modifyStatus(ids, id);
        return R.success("操作成功");
    }

    @GetMapping("/list")
    public R list(Long categoryId) {
        R r = dishService.list(categoryId);
        return r;
    }
}

